/***************************************************
 @Name :        小铭同学
 @Time :        2025-09-03
 @Email :       LiaoMingWJ233@163.com
 @Comment :     TCP服务器
 @FileName :    tcp.h
 @Version :     1.0
****************************************************/


#ifndef TCP_H
#define TCP_H

#include <QWidget>
#include <QtNetwork>
#include <QTcpServer>
#include <QTcpSocket>
#include <QMessageBox>
#include <QDebug>
#include <QDateTime>
#include <QKeyEvent>
#include <QFocusEvent>
#include <QPixmap>

class TCP : public QWidget
{
    Q_OBJECT
public:
    // 删除拷贝构造函数和赋值运算符
    TCP(const TCP&) = delete;
    TCP& operator=(const TCP&) = delete;
    
    // 获取单例实例的静态方法
    static TCP* instance(QWidget *parent = nullptr);
    
    QTcpSocket *clientSocket;
    QList<QTcpSocket*> clientSockets;
    QTcpServer *tcpServer;
    QTextCodec *m_gbkCodec;     
    
    int a=0;
    int b=0;
    int c=0;
    int d=0;
    
    void startServer();
    void stopServer();
    
    QString onReadyRead();
    void onSendButtonClicked(QString message);
    void onClientDisconnected();
    
private:   
    // 私有构造函数
    explicit TCP(QWidget *parent = nullptr);
    
    // 静态单例指针
    static TCP* m_instance;

private slots:
    void onNewConnection();            
    
signals:
    void statusChanged_fwd_lj();
    void statusChanged_fwd_dk();
    void statusChanged_khd_lj();
    void statusChanged_khd_dk();  
    
    // 数据接收信号
    void dataReceived(const QString &data);
};

#endif // TCP_H
